home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / highlight / highlight-W32GUI-2.2-10b-Setup.exe / {app} / src / languagedefinition.h < prev    next >
C/C++ Source or Header  |  2005-03-31  |  6KB  |  192 lines

  1. /***************************************************************************
  2.                           languagedefinition.h  -  description
  3.                              -------------------
  4.     begin                : Wed Nov 28 2001
  5.     copyright            : (C) 2001 by Andre Simon
  6.     email                : andre.simon1@gmx.de
  7.  ***************************************************************************/
  8.  
  9. /***************************************************************************
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  ***************************************************************************/
  17.  
  18. #ifndef LANGUAGEDEFINITION_H
  19. #define LANGUAGEDEFINITION_H
  20.  
  21. #include <string>
  22. #include <map>
  23. #include <iostream>
  24. #include <fstream>
  25. #include <iterator>
  26. #include <sstream>
  27.  
  28. #include "configurationreader.h"
  29. //#include "stringtools.h"
  30. #include "platform_fs.h"
  31. #include "enums.h"
  32.  
  33.  
  34. namespace highlight {
  35.  
  36. /** maps keywords and the corresponding class IDs*/
  37. typedef map <string, int> KeywordMap;
  38.  
  39. /** maps keyword prefixes and the corresponding class IDs*/
  40. typedef map <unsigned char, int> PrefixMap;
  41.  
  42. /**\brief Contains specific data of the programming language being processed.
  43.  
  44.    The load() method will only read a new language definition if the given
  45.    file path is not equal to the path of the current language definition.
  46.  
  47. * @author Andre  Simon
  48. */
  49.  
  50. class LanguageDefinition  {
  51.  
  52.   public:
  53.  
  54.     LanguageDefinition();
  55.  
  56.     /**\return Symbol string, containg all known symbols with the referencing state ids*/
  57.     string &getSymbolString();
  58.  
  59.     /** \return Prefix of raw strings */
  60.     unsigned char getRawStringPrefix();
  61.  
  62.    /** \return Continuation Character */
  63.     unsigned char getContinuationChar();
  64.  
  65.     /** \return List of characters allowed within identifiers */
  66.     string &getAllowedChars();
  67.  
  68.     /** \return true if syntax highlighting is enabled*/
  69.     bool getSyntaxHighlight();
  70.  
  71.     /** \return True if language is case sensitive */
  72.     bool isIgnoreCase();
  73.  
  74.     /** \param s String
  75.          \return class id of keyword, 0 if s is not a keyword */
  76.     int isKeyword(const string &s);
  77.  
  78.  
  79.     /** \return true if c is member of prefix list*/
  80.     bool isPrefix(unsigned char c);
  81.  
  82.     /** Load new language definition
  83.         \param langDefPath Path of language definition
  84.         \param clear Test if former data should be deleted
  85.         \return True if successfull  */
  86.     bool load(const string& langDefPath, bool clear=true);
  87.  
  88.     /** \return  True if programming language is VHDL */
  89.     bool isVHDL();
  90.  
  91.     /** \return  True if programming language is Java */
  92.     bool isJava();
  93.  
  94.     /** \return True if multi line comments may be nested */
  95.     bool allowNestedMLComments();
  96.  
  97.     /** \return True if highlighting is disabled */
  98.     bool highlightingDisabled();
  99.  
  100.     /** \return True if single line comments must start at coloumn 1 */
  101.     bool isFullLineComment();
  102.  
  103.     /** \return True the next load() call will load a new language definition
  104.         \param  langDefPath Path to language definition  */
  105.     bool needsReload(const string &langDefPath);
  106.  
  107.     /** \return True if current language may be reformatted (c, c++, c#, java) */
  108.     bool enableReformatting();
  109.  
  110.     /** \return True if escape sequences are allowed outsde of strings */
  111.     bool allowExtEscSeq();
  112.  
  113.     /** \return Class ID of given keyword delimiter prefix
  114.         \param prefix Keyword delimiter prefix   */
  115.     unsigned int getDelimPrefixClassID(const string& prefix);
  116.  
  117.     /** \return keywords*/
  118.     const KeywordMap& getKeywords() const;
  119.  
  120.     /** \return keyword classes*/
  121.     const vector<string>& getKeywordClasses() const;
  122.  
  123.   private:
  124.     // string containing symbols and their IDs of the programming language
  125.     string symbolString;
  126.  
  127.     // string with special characters that may occour in keywords
  128.     string allowedChars;
  129.  
  130.     // path to laoed language definition
  131.     string currentPath;
  132.  
  133.     KeywordMap keywords;
  134.  
  135.     vector <string> keywordClasses;
  136.  
  137.     KeywordMap delimiterPrefixes;
  138.  
  139.     PrefixMap prefixes;
  140.  
  141.     // keywords are not case sensitive if set
  142.     bool ignoreCase,
  143.     disableHighlighting,
  144.     allowExtEscape,
  145.  
  146.     // switch to enable VHDL workarounds
  147.     vhdl_mode,
  148.  
  149.     // switch to enable Java workarounds
  150.     java_mode,
  151.  
  152.     // allow nested multi line comment blocks
  153.     allowNestedComments,
  154.  
  155.     // single line comments have to start in coloumn 1 if set
  156.     fullLineComment,
  157.  
  158.     // code formatting is enabled if set
  159.     reformatCode;
  160.  
  161.     // Character, die eine Variable bzw. ein Keyword kennzeichnen
  162.     unsigned char rawStringPrefix,
  163.                   continuationChar;
  164.  
  165.     /** setzt Membervariablen auf Defaultwerte */
  166.     void reset();
  167.  
  168.     // add a symbol sequencs to the symbolStream
  169.     void addSimpleSymbol(stringstream& symbolStream, State state,
  170.                          const string& paramValues );
  171.  
  172.     // add a delimiter symbol sequencs to the symbolStream
  173.     void addDelimiterSymbol(stringstream& symbolStream,
  174.                             State stateBegin, State stateEnd,
  175.                             const string& paramValues,
  176.                             unsigned int classID=0);
  177.  
  178.     bool getFlag( string& paramValue);
  179.  
  180.     unsigned char getSymbol(const string& paramValue);
  181.  
  182.     // generate a unique class ID if the class name
  183.     unsigned int generateNewKWClass(const string& newClassName);
  184.  
  185.     // add keywords to the given class
  186.     void addKeywords(const string &kwList, int classID);
  187.  
  188.   };
  189.  
  190. }
  191. #endif
  192.